
const fs=require('fs');
const loading=require('loading-cli');//加载插件
const peotryList=fs.readFileSync('./poetry.txt','utf-8').split(','); 
const chalk=require('chalk');//颜色插件

const randomNum=()=>Math.floor(Math.random()*(peotryList.length-1)) ;//生成随机下标

const randomColor=(max,min)=>Math.floor(Math.random()*(max-min)+min) ;//随机颜色

let timer=null;
let date=0;
exports.actionHandle=(options)=>{

    if(options.s){
        const load=loading({
            text:"正在打印诗句",
            color:"blue",
            interval:100,
            stream: process.stdout,
            frames:["◐", "◓", "◑", "◒"]
        });
        load.start();
       timer= setInterval(()=>{
           date=++date
            console.log(chalk.rgb(randomColor(255,0),randomColor(255,0),randomColor(255,0))(peotryList[randomNum()]));//rgb三色
            if(date==15){
               clearInterval(timer);//清除定时器
               load.stop();//停止
            }
        },500)

    }
    
console.log();
}